home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
print
/
gs261sr1.zip
/
GDEVWPRN.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-05-12
|
19KB
|
646 lines
/* Copyright (C) 1989, 1992, 1993 Aladdin Enterprises. All rights reserved.
This file is part of Ghostscript.
Ghostscript is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY. No author or distributor accepts responsibility
to anyone for the consequences of using it or for whether it serves any
particular purpose or works at all, unless he says so in writing. Refer
to the Ghostscript General Public License for full details.
Everyone is granted permission to copy, modify and redistribute
Ghostscript, but only under the conditions described in the Ghostscript
General Public License. A copy of this license is supposed to have been
given to you along with Ghostscript so you can know your rights and
responsibilities. It should be in a file named COPYING. Among other
things, the copyright notice and this notice must be preserved on all
copies. */
/* gdevwprn.c */
/*
* Microsoft Windows 3.n printer driver for Ghostscript.
* Original version by Russell Lang and
* L. Peter Deutsch, Aladdin Enterprises.
*/
#include "gdevmswn.h"
#include "gp.h"
#include "commdlg.h"
/*
****** NOTE: this module and gdevwddb should be refactored.
* The drawing routines are almost identical.
* The differences are that the mswinprn doesn't use an extra
* palette (gdevwddb.c could probably be made to work with
* one palette also), mswinprn doesn't call win_update() because
* hwndimg doesn't exist, and the HDC is hdcmf not hdcbit.
******/
/* Make sure we cast to the correct structure type. */
typedef struct gx_device_win_prn_s gx_device_win_prn;
#undef wdev
#define wdev ((gx_device_win_prn *)dev)
/* Forward references */
private void near win_prn_addtool(P2(gx_device_win_prn *, int));
private void near win_prn_maketools(P2(gx_device_win_prn *, HDC));
private void near win_prn_destroytools(P1(gx_device_win_prn *));
/* Device procedures */
/* See gxdevice.h for the definitions of the procedures. */
private dev_proc_open_device(win_prn_open);
private dev_proc_close_device(win_prn_close);
private dev_proc_sync_output(win_prn_sync_output);
private dev_proc_output_page(win_prn_output_page);
private dev_proc_map_rgb_color(win_prn_map_rgb_color);
private dev_proc_fill_rectangle(win_prn_fill_rectangle);
private dev_proc_tile_rectangle(win_prn_tile_rectangle);
private dev_proc_copy_mono(win_prn_copy_mono);
private dev_proc_copy_color(win_prn_copy_color);
private dev_proc_draw_line(win_prn_draw_line);
/* The device descriptor */
struct gx_device_win_prn_s {
gx_device_common;
gx_device_win_common;
/* Handles */
HPEN hpen, *hpens;
uint hpensize;
HBRUSH hbrush, *hbrushs;
uint hbrushsize;
#define select_brush(color)\
if (wdev->hbrush != wdev->hbrushs[color])\
{ wdev->hbrush = wdev->hbrushs[color];\
SelectObject(wdev->hdcmf,wdev->hbrush);\
}
/* A staging bitmap for copy_mono. */
/* We want one big enough to handle the standard 16x16 halftone; */
/* this is also big enough for ordinary-size characters. */
#define bmWidthBytes 4 /* must be even */
#define bmWidthBits (bmWidthBytes * 8)
#define bmHeight 32
HBITMAP FAR hbmmono;
HDC FAR hdcmono;
gx_bitmap_id bm_id;
HDC hdcprn;
HDC hdcmf;
char mfname[128];
DLGPROC lpfnAbortProc;
};
private gx_device_procs win_prn_procs = {
win_prn_open,
gx_default_get_initial_matrix,
win_prn_sync_output,
win_prn_output_page,
win_prn_close,
win_prn_map_rgb_color,
win_map_color_rgb,
win_prn_fill_rectangle,
win_prn_tile_rectangle,
win_prn_copy_mono,
win_prn_copy_color,
win_prn_draw_line,
gx_default_get_bits,
gx_default_get_props,
gx_default_put_props,
gx_default_map_cmyk_color,
win_get_xfont_procs
};
gx_device_win_prn gs_mswinprn_device = {
sizeof(gx_device_win_prn),
&win_prn_procs,
"mswinprn",
INITIAL_WIDTH, INITIAL_HEIGHT, /* win_prn_open() fills these in later */
INITIAL_RESOLUTION, INITIAL_RESOLUTION, /* win_prn_open() fills these in later */
no_margins,
dci_black_and_white,
0, /* not open yet */
2, /* nColors */
};
/* Open the win_prn driver */
private int
win_prn_open(gx_device *dev)
{ int depth;
PRINTDLG pd;
FILE *f;
POINT offset;
POINT size;
_fmemset(&pd, 0, sizeof(PRINTDLG));
pd.lStructSize = sizeof(PRINTDLG);
pd.hwndOwner = hwndtext;
pd.Flags = PD_PRINTSETUP | PD_RETURNDC;
if (!PrintDlg(&pd)) {
/* device not opened - exit ghostscript */
return gs_error_limitcheck;
}
GlobalFree(pd.hDevMode);
GlobalFree(pd.hDevNames);
pd.hDevMode = pd.hDevNames = NULL;
wdev->hdcprn = pd.hDC;
if (!(GetDeviceCaps(wdev->hdcprn, RASTERCAPS) != RC_BITBLT)) {
DeleteDC(wdev->hdcprn);
return gs_error_limitcheck;
}
wdev->lpfnAbortProc = (DLGPROC)MakeProcInstance((FARPROC)AbortProc,phInstance);
Escape(wdev->hdcprn,SETABORTPROC,0,(LPSTR)wdev->lpfnAbortProc,NULL);
if (Escape(wdev->hdcprn, STARTDOC, strlen(szAppName),szAppName, NULL) <= 0) {
FreeProcInstance((FARPROC)wdev->lpfnAbortProc);
DeleteDC(wdev->hdcprn);
return gs_error_limitcheck;
}
f = gp_open_scratch_file(gp_scratch_file_name_prefix,
wdev->mfname, "wb");
if (f == (FILE *)NULL) {
Escape(wdev->hdcprn,ENDDOC,0,NULL,NULL);
FreeProcInstance((FARPROC)wdev->lpfnAbortProc);
DeleteDC(wdev->hdcprn);
return gs_error_limitcheck;
}
unlink(wdev->mfname);
wdev->hdcmf = CreateMetaFile(wdev->mfname);
dev->x_pixels_per_inch = GetDeviceCaps(wdev->hdcprn, LOGPIXELSX);
dev->y_pixels_per_inch = GetDeviceCaps(wdev->hdcprn, LOGPIXELSY);
Escape(wdev->hdcprn, GETPHYSPAGESIZE, NULL, NULL, (LPPOINT)&size);
dev->width = size.x;
dev->height = size.y;
Escape(wdev->hdcprn, GETPRINTINGOFFSET, NULL, NULL, (LPPOINT)&offset);
dev->l_margin = offset.x / dev->x_pixels_per_inch;
dev->t_margin = offset.y / dev->y_pixels_per_inch;
dev->r_margin =
(size.x - offset.x - GetDeviceCaps(wdev->hdcprn, HORZRES))
/ dev->x_pixels_per_inch;
dev->b_margin =
(size.y - offset.y - GetDeviceCaps(wdev->hdcprn, VERTRES))
/ dev->y_pixels_per_inch
+ 0.15; /* hack to add a bit more margin for deskjet printer */
wdev->hdctext = NULL;
/* Set parameters that were unknown before opening device */
/* Find out if the device supports color */
/* We recognize 2, 16 or 256 color devices */
depth = GetDeviceCaps(wdev->hdcprn,PLANES) * GetDeviceCaps(wdev->hdcprn,BITSPIXEL);
if ( depth >= 8 ) { /* use 64 static colors and 166 dynamic colors from 8 planes */
static const gx_device_color_info win_256color = dci_color(8,31,4);
dev->color_info = win_256color;
wdev->nColors = 64;
}
else if ( depth >= 4 ) {
static const gx_device_color_info win_16ega_color = dci_color(4, 2, 3);
dev->color_info = win_16ega_color;
wdev->nColors = 16;
}
else { /* default is black_and_white */
wdev->nColors = 2;
}
/* create palette for display */
if ((wdev->limgpalette = win_makepalette((gx_device_win *)dev))
== (LPLOGPALETTE)NULL) {
HMETAFILE hmf = CloseMetaFile(wdev->hdcmf);
DeleteMetaFile(hmf);
unlink(wdev->mfname);
Escape(wdev->hdcprn,ENDDOC,0,NULL,NULL);
FreeProcInstance((FARPROC)wdev->lpfnAbortProc);
DeleteDC(wdev->hdcprn);
return win_nomemory();
}
wdev->himgpalette = CreatePalette(wdev->limgpalette);
/* Create the bitmap and DC for copy_mono. */
wdev->hbmmono = CreateBitmap(bmWidthBits, bmHeight, 1, 1, NULL);
wdev->hdcmono = CreateCompatibleDC(wdev->hdcprn);
if ( wdev->hbmmono == NULL || wdev->hdcmono == NULL ) {
HMETAFILE hmf = CloseMetaFile(wdev->hdcmf);
DeleteMetaFile(hmf);
unlink(wdev->mfname);
Escape(wdev->hdcprn,ENDDOC,0,NULL,NULL);
FreeProcInstance((FARPROC)wdev->lpfnAbortProc);
DeleteDC(wdev->hdcprn);
gs_free((char *)(wdev->limgpalette), 1, sizeof(LOGPALETTE) +
(1<<(wdev->color_info.depth)) * sizeof(PALETTEENTRY),
"win_prn_open");
return win_nomemory();
}
SetMapMode(wdev->hdcmono, GetMapMode(wdev->hdcprn));
SelectObject(wdev->hdcmono, wdev->hbmmono);
(void) SelectPalette(wdev->hdcmf,wdev->himgpalette,NULL);
RealizePalette(wdev->hdcmf);
win_p